/*******************************************************************************
																				
	DESCRIPTION:  	This do file produces the histograms of the duration dependence
					estimated parameters.

*******************************************************************************/

clear all
global id_code 119_4
pause on
set seed 2110


* Set globals:
global model Full	
global y0 2006
global y1 2006
global pred ""

if $y0 != $y1 {
	global y "Pooled_${y0}_${y1}"
}
else if $y0 == $y1 {
	global y $y0
}
		
			
*******************************************************************************
* Load data
*******************************************************************************
use "${data}/119_3_DurationDependenceBetas_Full_${y}${pred}.dta", clear

*******************************************************************************
* Create distributions of shrunken variables
*******************************************************************************
* Calculate e^beta_0
gen exp_beta_0_shrunk_ind = exp(beta_0_shrunk_ind)

* Calculate 20th and 80th percentiles
sum exp_beta_0_shrunk_ind
local mean_0 : di %9.3f r(mean)
local sd_0 : di %9.3f `=`r(sd)''
local var_0 : di %9.3f `=`r(sd)'^2'

_pctile exp_beta_0_shrunk_ind, p(20 80)
local p20_0 : di %9.3f `r(r1)'
local p80_0 : di %9.3f `r(r2)'

sum beta_1_shrunk_ind
local mean_1 : di %9.3f r(mean)
local sd_1 : di %9.3f `=`r(sd)''
local var_1 : di %9.3f `=`r(sd)'^2'

_pctile beta_1_shrunk_ind, p(20 80)
local p20_1: di %9.3f `r(r1)'
local p80_1: di %9.3f `r(r2)'

* Bootstrap the shrunken coefficients:
bootstrap r(sd), reps(500) seed(2110) verbose: sum beta_1_shrunk_ind

di "The 20th percentile of beta_1 corresponds to a decline of `=600*`r(r1)''% over 6M."		
qui sum beta_1_shrunk_ind
di "The average beta_1 corresponds to a decline of `=600*`r(mean)''% over 6M."
count if beta_1_shrunk_ind < .
local N = r(N)
count if beta_1_shrunk_ind >= 0
local Nplus = r(N)

di "For `=100* `Nplus'/`N''% of job seekers, the JFR does not decline."

histogram exp_beta_0_shrunk_ind if exp_beta_0_shrunk_ind<1, frequency  width(0.025) fcolor(ebblue*0.5) lcolor(ebblue) ///
	legend(on order( ///
		- "Mean = `mean_0'" ///
		- "Std. Dev. = `sd_0'") ///
		symxsize(*0.5) size(small) cols(1) pos(10) ring(0) justification(right) placement(right) )			///
	graphregion(color(white)) /// 	
	plotregion(margin(b=0 y=0)) ///
	xaxis(1 2)					///
	ytitle("Frequency", size(9pt)) ///
	xtitle("exp({&beta}{sub:0})", axis(1) size(9pt)) ///
	xtitle("", axis(2))		///
	ylabel(0(2500)10000, format(%11.0fc) labsize(10pt) angle(0)) yscale(titlegap(2)) ///
	xscale(titlegap(2) axis(1)) xlabel(0(0.5)1, axis(1))	///
	xscale(noline axis(2)) ///
	xlabel(none, value axis(2) noticks) ///
	name(dist_beta0, replace)
	
graph export "${output}/${id_code}_DurationDependence_${model}_${y}${pred}_Distribution_ExpBeta0Shrunken.pdf", as(pdf) replace
		
histogram beta_1_shrunk_ind if inrange(beta_1_shrunk_ind,`=-1/12',`=1/12'), frequency  width(`=0.025/6') fcolor(ebblue*0.5) lcolor(ebblue) ///
	legend(on order( ///
		- "Mean = `mean_1'" ///
		- "Std. Dev. = `sd_1'") ///
		symxsize(*0.5) size(small) cols(1) pos(2) ring(0) justification(right) placement(right) )			///
	graphregion(color(white)) /// 	
	plotregion(margin(b=0 y=0)) ///
	xaxis(1 2)					///
	ytitle("Frequency", size(9pt)) ///
	xtitle("{&beta}{sub:D}", size(9pt)) ///
	xtitle("", axis(2))		///
	ylabel(0(2500)32500, format(%11.0fc) labsize(10pt) angle(0)) yscale(titlegap(2)) ///
	xlabel(-0.075(0.025)0.075, axis(1)) ///
	xscale(titlegap(2) axis(1))			///
	xscale(noline axis(2)) ///
	xlabel(none, value axis(2) noticks) ///
	name(dist_beta1, replace)
graph export "${output}/${id_code}_DurationDependence_${model}_${y}${pred}_Distribution_BetaDShrunken.pdf", as(pdf) replace				
